/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <向量.h>


CUDA_CALLABLE inline vec4 f_quat_轴旋转(const vec3& axis, float angle) {
	//Vec3 v = Normalize(axis);

	float half = angle * 0.5f;
	float w = cosf(half);

	const float32 sin_theta_over_two = sinf(half);
	vec3 v = vec_mul(axis, sin_theta_over_two);

	return { v.x, v.y, v.z, w };
}





CUDA_CALLABLE inline vec3 f_quat_Rotate(const vec4& q, const vec3& inPoint) {
	vec3 xyz;// *0.5f;

	/*xyz = vec_multi(inPoint, q.w * q.w - 0.5f);
	vec_multi(&xyz, 2.0f);
	vec_add(&xyz, vec_multi(vec_cross(q, inPoint), q.w));
	vec_add(&xyz, vec_multi(vec_转换v3(q), vec_dot(q, inPoint)));*/


	xyz = vec_mul(inPoint, 2.0f * q.w * q.w - 1.0f);
	vec_add(&xyz, vec_mul(vec_mul(vec_cross(q, inPoint), q.w), 2));
	vec_add(&xyz, vec_mul(vec_mul(vec_转换v3(q), vec_dot(q, inPoint)), 2.0f));
	
	return xyz;
}











